<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>设备信息</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <input type="hidden" name="id" id="id" value="${cameraInfo.id!}">
                <div class="layui-form-item">
                    <label class="layui-form-label">设备名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="camera_name" lay-verify="required" value="${cameraInfo.camera_name!}" autocomplete="off" placeholder="请输入设备名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备类型</label>
                    <div class="layui-input-block">
                        <select name="camera_type" lay-verify="required">
                            <option value="" selected>请选择</option>
                            <option value="1" ${cameraInfo.camera_type!0=='1'?'selected':''}>移动布控球</option>
                            <option value="2" ${cameraInfo.camera_type!0=='2'?'selected':''}>固定摄像头</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备编号</label>
                    <div class="layui-input-block">
                        <input type="text"  name="camera_num" lay-verify="required|isExist" value="${cameraInfo.camera_num!}" autocomplete="off" placeholder="请输入设备编号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">监控点编号</label>
                    <div class="layui-input-block">
                        <input type="text"  name="camera_code" lay-verify="required" value="${cameraInfo.camera_code!}" autocomplete="off" placeholder="请输入监控点编号" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">专业类型</label>
                    <div class="layui-input-block">
                        <select name="yyly" lay-verify="required">
                            <option value="" selected>请选择</option>
                            @for(item in professionalTypeList!){
                            <option value="${item.id}" ${item.id==(cameraInfo.yyly!)?'selected':''}>${item.name!}</option>
                            @}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">变电站</label>
                    <div class="layui-input-block">
                        <input type="text"  name="substation" lay-verify="required" value="${cameraInfo.substation!}" autocomplete="off" placeholder="请输入变电站" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">视频流</label>
                    <div class="layui-input-block">
                        <input type="text" name="stream" value="${cameraInfo.stream!}" autocomplete="off" placeholder="请输入视频流地址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea name="remark" placeholder="请输入备注" autocomplete="off" class="layui-textarea">${cameraInfo.remark!}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="del_flag" lay-skin="switch" lay-text="启用|禁用" ${cameraInfo.del_flag!'0'=='0'?'checked':''}>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;

        let MODULE_PATH = "${ctxPath}/camera/";

        form.on('submit(user-save)', function(data){
            data.field.del_flag = data.field.del_flag == "on"?0:1;
            $.ajax({
                url: MODULE_PATH + 'data/save',
                data:JSON.stringify(data.field),
                dataType:'json',
                contentType:'application/json',
                type:'post',
                success:function(result){
                    if(result.code == 0){
                        layer.msg(result.message,{icon:1,time:1000},function(){
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("camera-table");
                        });
                    }else{
                        layer.msg(result.message,{icon:2,time:1000});
                    }
                }
            })
            return false;
        });

        form.verify({
            isExist:function(value){
                var data;
                var id = $("#id").val();
                $.ajax({
                    url: MODULE_PATH + 'data/isExist',
                    data: {
                        'camera_num': value,
                        'id': id
                    },
                    dataType:'json',
                    contentType:'application/json',
                    type:'get',
                    async: false,
                    success:function(result){
                        console.info(result);
                        if(result&&result>0){
                            data=true;
                        }
                    }
                });
                if(data){
                    return '设备编号已存在';
                }
            }
        });
    })
</script>
<script>
</script>
</body>
</html>